#!/usr/bin/python
# -*- coding: utf-8 -*-

### BEGIN LICENSE
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.
### END LICENSE

import sys
import os
import signal
import glob
import fcntl
import shutil
import logging
import tempfile
import subprocess
import re
import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import GObject
import threading
import thread
from server import PolicyKitService
import time

from get_activation import GetActivation

log = logging.getLogger('Daemon')


INTERFACE = 'com.kylin.activation'
UKPATH = '/'

class Daemon(PolicyKitService):
    def __init__ (self, bus, mainloop):
        self.getactivation = GetActivation()

        bus_name = dbus.service.BusName(INTERFACE, bus=bus)
        PolicyKitService.__init__(self, bus_name, UKPATH)
        self.mainloop = mainloop

    @dbus.service.method(INTERFACE, in_signature='', out_signature='')
    def exit(self):
        self.mainloop.quit()

    @dbus.service.method(INTERFACE, in_signature='', out_signature='as')
    def get_serial_number(self):
        return self.getactivation.get_serial_number()

    @dbus.service.method(INTERFACE, in_signature='', out_signature='as')
    def get_register_number(self):
        return self.getactivation.get_register_number()

    @dbus.service.method(INTERFACE, in_signature='', out_signature='as')
    def get_qrcode(self):
        return self.getactivation.get_qrcode()

    @dbus.service.method(INTERFACE, in_signature='s', out_signature='s')
    def activation_activate_system(self,acti):
        return self.getactivation.activation_activate_system(acti)
